package com.fengdi.mapper;

import com.fengdi.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


@Mapper
public interface UserMapper {

    // 根据用户名查询
    @Select("SELECT * FROM user WHERE username = #{username}")
    User findByUsername(String username);

    // 添加一条新的用户数据
    @Insert("INSERT INTO user(username, password, create_time, update_time) VALUES (#{username}, #{password}, NOW(), NOW())")
    void insertUser(String username, String password);

    // 跟新一条用户数据
    @Update("UPDATE user SET nickname=#{nickname},email=#{email},update_time=#{updateTime} WHERE id=#{id}")
    void updateUser(User user);

    //更新头像
    @Update("UPDATE user SET user_pic=#{avatarUrl} WHERE username=#{username}")
    void updateUserPic(String username, String avatarUrl);

    // 根据用户名更新密码
    @Update("UPDATE user SET password = #{newPwd},update_time = #{updateTime} WHERE username = #{username}")
    void updateUserPwdByUsername(String username, String newPwd, String updateTime);

}
